﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.DAL;

namespace WXYW
{
    public partial class EditProductClass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindProductClassInfo();
            }
        }

        private void BindProductClassInfo()
        {
            int productClassID = Convert.ToInt32(Request.QueryString[Constants.QUERYSTR_PRODUCT_CLASS_ID]);
            ProductClassService service = new ProductClassService();
            ProductClass productClass = service.GetProductClass(productClassID);

            NameTxtBox.Text = productClass.Name;
            Description.Text = productClass.Description;
            IsOEMTypeCheckBox.Checked = productClass.IsOEM;
        }

        protected void okLnkBtn_Click(object sender, EventArgs e)
        {
            try
            {
                int productClassID = Convert.ToInt32(Request.QueryString[Constants.QUERYSTR_PRODUCT_CLASS_ID]);
                ProductClassService service = new ProductClassService();
                ProductClass productClass = service.GetProductClass(productClassID);

                productClass.Name = NameTxtBox.Text.Trim();
                productClass.Description = Description.Text.Trim();
                if (IsOEMTypeCheckBox.Checked)
                {
                    productClass.IsOEM = true;
                }
                else
                {
                    productClass.IsOEM = false;
                }

                service.UpdateProductClass(productClass);
                //MsgLbl.Text = "修改成功！";
            }
            catch (Exception ex)
            {
                MsgLbl.Text = string.Format("系统错误：{0}", ex.Message);
                LogUtility.LogUtilityIntance.LogException(ex, string.Format("EditProductClass -> OKBtn_Click:{0}", NameTxtBox.Text));
            }
        }

        protected void backLnkBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("ManageProductClass.aspx");
        }
    }
}
